package com.ctl.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctl.dto.FeedAllDTO;
import com.ctl.entity.Category;
import com.ctl.entity.Feed;
import com.ctl.mapper.CategoryMapper;
import com.ctl.service.FeedService;
import com.ctl.mapper.FeedMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author stars
* @description 针对表【feed(动态)】的数据库操作Service实现
* @createDate 2023-03-02 19:15:52
*/
@Service
public class FeedServiceImpl extends ServiceImpl<FeedMapper, Feed>
    implements FeedService{
    @Autowired
    private FeedMapper mapper;
    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public List<FeedAllDTO> getFeedsPage(Integer page, Integer perPage) {
        List<FeedAllDTO> feedsAll = mapper.getFeedsAll((page - 1) * perPage, perPage);
        for (FeedAllDTO feedAllDTO : feedsAll) {
            Category category = categoryMapper.selectById(feedAllDTO.getCategory_id());
            if (category!=null){
                feedAllDTO.getVideo().setCategory(category.getName());
            }
            if (feedAllDTO.getImages()!=null){
                String[] strings = feedAllDTO.getImages().split(" ");
                feedAllDTO.setImagesStr(strings);
            }
        }
        return feedsAll;
    }
}




